/**
 * 
 */
package model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;


/**
 * @author annvcit
 * @full_name Nguyen Van Chuc An
 * @date_created Dec 23, 2014
 * @email annvcit@gmail.com
 */
public class StudentDAO {
	public ArrayList<Student> getStudents(String class_id) {
		ArrayList<Student> list = new ArrayList<>();
		try {
			Connection connection = DBConnection.getConnection();
			String sql = "SELECT * FROM Student WHERE CLASS_ID=?";
			PreparedStatement pr = connection.prepareStatement(sql);
			pr.setString(1, class_id);
			ResultSet rs = pr.executeQuery();
			while (rs.next()) {
				String STUDENT_ID = rs.getString("STUDENT_ID");
				String CLASS_ID = rs.getString("CLASS_ID");
				String STUDENT_NAME = rs.getString("STUDENT_NAME");
				String STUDENT_ADDRESS = rs.getString("STUDENT_ADDRESS");
				String STUDENT_PHONE = rs.getString("STUDENT_PHONE");
				Student st = new Student(STUDENT_ID, CLASS_ID,
						STUDENT_NAME, STUDENT_ADDRESS, STUDENT_PHONE);
				list.add(st);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
}
